package org.xu.upms.client;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.xu.upms.client.rpc.AuthenticationRpcService;

import com.xu.commons.config.ConfigUtils;

/**
 * 过滤器
 * @author xupeijiao
 *
 */
public abstract class ClientFilter  implements Filter {
	// 单点登录服务端URL
		protected String ssoServerUrl;
		// 当前应用关联权限系统的应用编码
		protected String ssoAppCode;
		protected AuthenticationRpcService authenticationRpcService;

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doFilter(ServletRequest request,
			ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		this.ssoServerUrl=ConfigUtils.getProperties("sso.server.url");
		this.ssoAppCode="ssoAppCode";
		WebApplicationContext webApp = ContextLoader.getCurrentWebApplicationContext();
		authenticationRpcService =webApp.getBean(AuthenticationRpcService.class);
		HttpServletRequest httpRequest = (HttpServletRequest) request;
		httpRequest.getServletPath();
		//请求不是需要登录的地址直接放过
		//chain.doFilter(request, response);
		HttpServletResponse httpResponse = (HttpServletResponse)response;
		doFilter(httpRequest,httpResponse,chain);
		
		
	}

	@Override
	public void init(FilterConfig paramFilterConfig) throws ServletException {
		
		
	}
	
	
	public abstract void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
			throws IOException, ServletException;

}
